package one.stand.eureka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author cjr
 */
@Component
@Slf4j
public class EurekaStateChangeListener {

    /**
     * 客户端下线触发事件
     */
//    @EventListener
//    public void listen(EurekaInstanceCanceledEvent event) {
//        String appName = event.getAppName();
//        String serverId = event.getServerId();
//        log.info("客户端下线触发事件: {} {} {}", appName, serverId);
//    }

    /**
     * 客户端服务注册事件
     */
//    @EventListener
//    public void listen(EurekaInstanceRegisteredEvent event) {
//        InstanceInfo app = event.getInstanceInfo();
//        log.info("客户端服务注册事件: {} {}", app.getAppName(), app.getIPAddr());
//    }

    /**
     * 客户端续约事件
     */
//    @EventListener
//    public void listen(EurekaInstanceRenewedEvent event) {
//        String appName = event.getAppName();
//        String serverId = event.getServerId();
//        log.info("客户端续约事件: {} {}", appName, serverId);
//    }

    @EventListener
    public void listen(EurekaRegistryAvailableEvent event) {
        log.info("Eureka服务端可用事件");
    }

    @EventListener
    public void listen(EurekaServerStartedEvent event) {
        log.info("Eureka服务端启动事件");
    }
}